package crypt.smallprince.com.crypt;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.smallkingson.ylib.core.Yr;
import com.smallkingson.ylib.core.utils.YSystems;

public class MainActivity extends Activity {

  // Used to load the 'native-lib' library on application startup.
  static {
    System.loadLibrary("crypt");
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Example of a call to a native method
//    TextView tv = (TextView) findViewById(R.id.sample_text);
//    tv.setText(""+Crypt.lk("308202bf308201a7a0030201020204613ab1d5300d06092a864886f70d01010b05003010310e300c0603550403130571746b6579301e170d3139303132373031333931305a170d3434303132313031333931305a3010310e300c0603550403130571746b657930820122300d06092a864886f70d01010105000382010f003082010a02820101009a91ad693bd04397c04da78966a065041f9c8418793d999b63e1c9495e4c4ba928e860c2eb54bf1e5ada20ad802ff99b7afc4eb610943dd5479d45c3eeb25d5099b7159bea74704190aa59f0c088787c4eb8d8e598ee5dd01a198630a80c2b52031859b5ac91c2b295718719bdfb036ae061e62f02fc7420067c682cf4c02b03868b8669b8f573c1aceffc7474b71fc7fca2d10c5929f4a85c0df971bfc5b9325d855ab33853c01e8b115710347268fe0eab4f84ca073dd3741e96e1df3a176e67d778be4db345944bab41ee4f73ced6fe3bb8ed7118d076ecbb61fdbe90a09771780a78ec6b7a0247c038dd60bcb5ab4ea07be205aafeb97d9bd0c5576ac3fd0203010001a321301f301d0603551d0e041604148193f2097f53a4c3ff5670c11af0359c990d54df300d06092a864886f70d01010b050003820101003d1e92e06f341f64ffe41c5f09ad94ee2b28fc1d6dc731aad475cb027de87d18cfb3ef78a12335c7a594c344d42376a5d0b2db7c045d63fad86d359ec4"));

//    tv.setText(Crypt.jk("308202bf308201a7a0030201020204613ab1d5300d06092a864886f70d01010b05003010310e300c0603550403130571746b6579301e170d3139303132373031333931305a170d3434303132313031333931305a3010310e300c0603550403130571746b657930820122300d06092a864886f70d01010105000382010f003082010a02820101009a91ad693bd04397c04da78966a065041f9c8418793d999b63e1c9495e4c4ba928e860c2eb54bf1e5ada20ad802ff99b7afc4eb610943dd5479d45c3eeb25d5099b7159bea74704190aa59f0c088787c4eb8d8e598ee5dd01a198630a80c2b52031859b5ac91c2b295718719bdfb036ae061e62f02fc7420067c682cf4c02b03868b8669b8f573c1aceffc7474b71fc7fca2d10c5929f4a85c0df971bfc5b9325d855ab33853c01e8b115710347268fe0eab4f84ca073dd3741e96e1df3a176e67d778be4db345944bab41ee4f73ced6fe3bb8ed7118d076ecbb61fdbe90a09771780a78ec6b7a0247c038dd60bcb5ab4ea07be205aafeb97d9bd0c5576ac3fd0203010001a321301f301d0603551d0e041604148193f2097f53a4c3ff5670c11af0359c990d54df300d06092a864886f70d01010b050003820101003d1e92e06f341f64ffe41c5f09ad94ee2b28fc1d6dc731aad475cb027de87d18cfb3ef78a12335c7a594c344d42376a5d0b2db7c045d63fad86d359ec4"));
//    tv.setText(Crypt.jk("308202bf308201a7a0030201020204613ab1d5300d06092a864886f70d01010b05003010310e300c0603550403130571746b6579301e170d3139303132373031333931305a170d3434303132313031333931305a3010310e300c0603550403130571746b657930820122300d06092a864886f70d01010105000382010f003082010a02820101009a91ad693bd04397c04da78966a065041f9c8418793d999b63e1c9495e4c4ba928e860c2eb54bf1e5ada20ad802ff99b7afc4eb610943dd5479d45c3eeb25d5099b7159bea74704190aa59f0c088787c4eb8d8e598ee5dd01a198630a80c2b52031859b5ac91c2b295718719bdfb036ae061e62f02fc7420067c682cf4c02b03868b8669b8f573c1aceffc7474b71fc7fca2d10c5929f4a85c0df971bfc5b9325d855ab33853c01e8b115710347268fe0eab4f84ca073dd3741e96e1df3a176e67d778be4db345944bab41ee4f73ced6fe3bb8ed7118d076ecbb61fdbe90a09771780a78ec6b7a0247c038dd60bcb5ab4ea07be205aafeb97d9bd0c5576ac3fd0203010001a321301f301d0603551d0e041604148193f2097f53a4c3ff5670c11af0359c990d54df300d06092a864886f70d01010b050003820101003d1e92e06f341f64ffe41c5f09ad94ee2b28fc1d6dc731aad475cb027de87d18cfb3ef78a12335c7a594c344d42376a5d0b2db7c045d63fad86d359ec4"));
  }

  /**
   * A native method that is implemented by the 'native-lib' native library, which is packaged with
   * this application.
   */
  public static String getSignature(Context context) {
    try {
      /** 通过包管理器获得指定包名包含签名的包信息 **/
      PackageInfo packageInfo = context.getPackageManager()
          .getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
      /******* 通过返回的包信息获得签名数组 *******/
      Signature[] signatures = packageInfo.signatures;
      /******* 循环遍历签名数组拼接应用签名 *******/
      return signatures[0].toCharsString();
      /************** 得到应用签名 **************/
    } catch (PackageManager.NameNotFoundException e) {
      e.printStackTrace();
    }
    return null;
  }

  public void jk(View view) {
    //    tv.setText(Crypt.jk("308202bf308201a7a0030201020204613ab1d5300d06092a864886f70d01010b05003010310e300c0603550403130571746b6579301e170d3139303132373031333931305a170d3434303132313031333931305a3010310e300c0603550403130571746b657930820122300d06092a864886f70d01010105000382010f003082010a02820101009a91ad693bd04397c04da78966a065041f9c8418793d999b63e1c9495e4c4ba928e860c2eb54bf1e5ada20ad802ff99b7afc4eb610943dd5479d45c3eeb25d5099b7159bea74704190aa59f0c088787c4eb8d8e598ee5dd01a198630a80c2b52031859b5ac91c2b295718719bdfb036ae061e62f02fc7420067c682cf4c02b03868b8669b8f573c1aceffc7474b71fc7fca2d10c5929f4a85c0df971bfc5b9325d855ab33853c01e8b115710347268fe0eab4f84ca073dd3741e96e1df3a176e67d778be4db345944bab41ee4f73ced6fe3bb8ed7118d076ecbb61fdbe90a09771780a78ec6b7a0247c038dd60bcb5ab4ea07be205aafeb97d9bd0c5576ac3fd0203010001a321301f301d0603551d0e041604148193f2097f53a4c3ff5670c11af0359c990d54df300d06092a864886f70d01010b050003820101003d1e92e06f341f64ffe41c5f09ad94ee2b28fc1d6dc731aad475cb027de87d18cfb3ef78a12335c7a594c344d42376a5d0b2db7c045d63fad86d359ec4"));
    String signature = YSystems.getSignature(this);
    Yr.e(signature);
    Yr.d(Crypt.jk(signature));
  }
}
